//
// Created by martin on 7/7/21.
//

#include "strex.h"
#include <string.h>
#include <ctype.h>
#include <sys/types.h>


void strex_trimcrlf(char *s)
{
    size_t len;
    ssize_t i;
    if (s == NULL) return;

    len = strlen(s);

    for (i = (ssize_t)len - 1; i >= 0; --i) {
        if (s[i] == '\n' || s[i] == '\r')
            s[i] = '\0';
    }
}

void strex_split(char *s, char *left, char *right, const char* delim)
{
    char *s1;
    char *s2;
    s1 = strtok_r(s, delim, &s2);

    if (s1 != NULL)
        strcpy(left, s1);
    if (s2 != NULL)
        strcpy(right, s2);
}


void strex_toupper(char *s)
{
    while (*s != '\0') {
        *s = toupper(*s);
        ++s;
    }
}
